package com.woniu.util;

import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

@AllArgsConstructor
@NoArgsConstructor
@Data
public class ResponseData<T> {
    private Integer code;
    private T data;
    private String msg;

    //封装两钟方法，一个是成功的方法，一个失败的方法
    public static<T> ResponseData<T> ok(){
        return new ResponseData<>(ResponseEnum.SUCCESS.getCode(),
                null,ResponseEnum.SUCCESS.getMsg());
    }

    public static<T> ResponseData ok(T data){
        return new ResponseData<>(ResponseEnum.SUCCESS.getCode(),
                data,
                ResponseEnum.SUCCESS.getMsg());
    }

    //失败情况下的分装

    public static <T> ResponseData<T> fail(ResponseEnum responseEnum){
        return new ResponseData<>(responseEnum.getCode(),null,responseEnum.getMsg());
    }
//    public static<T> ResponseData fail(Integer code){
//        return new ResponseData<>(code,null,"操作失败");
//    }
}
